package Bitwise;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Bitwise
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-23  20:35
 * @Description: TODO
 * @Version: 1.0
 */
public class 两整数之和371 {

    // 使用的位运算来是是是实现
    public int getSum(int a, int b) {
        while (b != 0) {
            int carry = (a & b) << 1;// 进位置
            a = a ^ b;// 进行的与运算加起来
            b = carry;
        }
        return a;
    }

    public int getSum2(int a, int b) {
        return (b==0)?a:getSum2(a^b,(a&b)<<1);
    }
}
